<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta content="HTML Tidy for Cygwin (vers 1st February 2003), see www.w3.org" name="generator">
    <meta name="keywords" content="electronic commerce, ecommerce, ebusiness, e-business, e-commerce, enterprise software, net economy, Netscape, Sun Microsystems, DevEdge Archive, iPlanet, internet software">
    <meta name="description" content="The DevEdge Archive, a strategic alliance formed by America Online and Sun Microsystems, Inc., is delivering iPlanet e-commerce software and enterprise solutions that enable companies to compete successfully in the Net Economy">
    <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
    <meta name="TEMPLATEBASE" content="Authored in FrameMaker. Converted to HTML in WebWorks Publisher 2000. manual wdt 1.5">
    <meta name="LASTUPDATED" content="09/28/00 13:15:28">
    <title>
      Core JavaScript Reference 1.5:
    </title>
    <link rel="stylesheet" type="text/css" href="js15ref.css">
  </head>
  <body>
    <table width="100%" border="0" cellspacing="4">
      <tr>
        <td valign="top">
          <b><a class="sansserifPurple" href="date.html">Previous</a></b>&nbsp;&nbsp;&nbsp;&nbsp; <a href="contents.html"><b class="sansserifPurple">Contents</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="ix.html"><b class="sansserifPurple">Index</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="java.html"><b class="sansserifPurple">Next</b></a> &nbsp;&nbsp;&nbsp;&nbsp;
        </td>
      </tr>
      <tr>
        <td class="sansserifBlack" valign="top" align="right" bgcolor="#CCCCCC">
          <b>Core JavaScript Reference 1.5</b>
        </td>
      </tr>
    </table><br>
     
    <blockquote>
      <br>
      <br>
      <br>
      <br>
       
      <p>
        <a name="1193137" id="1193137"></a> <a name="Function" id="Function"></a> <span class="sansserif"><b>Function</b></span>
      </p>
      <p>
        <a name="1237518" id="1237518"></a> <span class="sansserif">xxx I believe that I have removed all client-specific examples from this file.</span>
      </p>
      <p>
        <a name="1193161" id="1193161"></a> <span class="sansserif">Specifies a string of JavaScript code to be compiled as a function.<br></span>
      </p><br>
       
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top" colspan="2" rowspan="1">
            <p>
              <a name="1193141" id="1193141"></a> <span class="sansserif"><i>Core object</i></span>
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193145" id="1193145"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193147" id="1193147"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span>
            </p>
            <p>
              <a name="1194816" id="1194816"></a>
            </p>
            <p>
              <a name="1194817" id="1194817"></a> <span class="sansserif">JavaScript 1.2: added <a href="function.html#1231596">arity</a>, <a href="function.html#1196419">arguments.callee</a> properties; added ability to nest functions.</span>
            </p>
            <p>
              <a name="1193160" id="1193160"></a>
            </p>
            <p>
              <a name="1194822" id="1194822"></a> <span class="sansserif">JavaScript 1.3: added <a href="function.html#1194017">apply</a>, <a href="function.html#1194243">call</a>, and <a href="function.html#1193583">toSource</a> methods; deprecated <a href="function.html#1196447">arguments.caller</a> property.</span>
            </p>
            <p>
              <a name="1215008" id="1215008"></a>
            </p>
            <p>
              <a name="1215053" id="1215053"></a> <span class="sansserif">JavaScript 1.4: deprecated <a href="function.html#1193312">arguments</a>, <a href="function.html#1196419">arguments.callee</a>, <a href="function.html#1196484">arguments.length</a>, and <a href="function.html#1231596">arity</a> properties (<span class="mono">arguments</span> remains a variable local to a function rather than a property of <span class="mono">Function</span>).</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196892" id="1196892"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196894" id="1196894"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1213952" id="1213952"></a> <a name="Created by" id="Created by"></a> <span class="sansserif"><b>Created by</b></span><br>
         <a name="1213953" id="1213953"></a> <span class="sansserif">The <span class="mono">Function</span> constructor:</span>
      </p>
      <p>
        <a name="1213954" id="1213954"></a><span class="mono">new Function ([<i>arg1</i>[, <i>arg2</i>[, ... <i>argN</i>]],] <i>functionBody</i>)</span>
      </p>
      <p>
        <a name="1214901" id="1214901"></a> <span class="sansserif">The <span class="mono">function</span> statement (see <a href="stmt.html#1004825">function</a> for details):</span>
      </p>
      <p>
        <a name="1214924" id="1214924"></a> <span class="mono">function <i>name</i>([<i>param</i>[, <i>param</i>[, ... <i>param</i>]]]) {<br>
         &nbsp;&nbsp;&nbsp;<i>statements<br></i>}</span>
      </p>
      <p>
        <br>
         <a name="1213955" id="1213955"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1193175" id="1193175"></a> <span class="sansserif"><br></span>
      </p><br>
       
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <a name="1193168" id="1193168"></a> <span class="mono">arg1, arg2, ... arg<i>N</i></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193170" id="1193170"></a> <span class="sansserif">Names to be used by the function as formal argument names. Each must be a string that corresponds to a valid JavaScript identifier; for example <span class="mono">"x"</span> or <span class="mono">"theValue"</span>.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1193172" id="1193172"></a> <span class="mono">functionBody</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193174" id="1193174"></a> <span class="sansserif">A string containing the JavaScript statements comprising the function definition.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1224441" id="1224441"></a> <span class="mono">name</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1224443" id="1224443"></a> <span class="sansserif">The function name.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1224437" id="1224437"></a> <span class="mono">param</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1224439" id="1224439"></a> <span class="sansserif">The name of an argument to be passed to the function. A function can have up to 255 arguments.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1231929" id="1231929"></a> <span class="mono">statements</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1231931" id="1231931"></a> <span class="sansserif">The statements comprising the body of the function.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193176" id="1193176"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1218580" id="1218580"></a> <span class="sansserif"><span class="mono">Function</span> objects created with the <span class="mono">Function</span> constructor are evaluated each time they are used. This is less efficient than declaring a function and calling it within your code, because declared functions are compiled.</span>
      </p>
      <p>
        <a name="1218451" id="1218451"></a> <span class="sansserif">To return a value, the function must have a <a href="stmt.html#1004871">return</a> statement that specifies the value to return.</span>
      </p>
      <p>
        <a name="1218452" id="1218452"></a> <span class="sansserif">All parameters are passed to functions <i>by value</i>; the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function. However, if you pass an object as a parameter to a function and the function changes the object's properties, that change is visible outside the function, as shown in the following example:</span>
      </p>
      <p>
        <a name="1228173" id="1228173"></a> <span class="mono">function myFunc(theObject) {<br>
         &nbsp;&nbsp;&nbsp;theObject.make="Toyota"<br>
         }<br>
        <br>
         mycar = {make:"Honda", model:"Accord", year:1998}<br>
         x=mycar.make &nbsp;&nbsp;&nbsp;&nbsp;// returns Honda<br>
         myFunc(mycar) &nbsp;&nbsp;&nbsp;// pass object mycar to the function<br>
         y=mycar.make &nbsp;&nbsp;&nbsp;&nbsp;// returns Toyota (prop was changed by the function)</span>
      </p>
      <p>
        <a name="1224640" id="1224640"></a> <span class="sansserif">The <span class="mono">this</span> keyword does not refer to the currently executing function, so you must refer to <span class="mono">Function</span> objects by name, even within the function body.</span>
      </p>
      <p>
        <a name="1231645" id="1231645"></a> <span class="sansserif"><b>Accessing a function's arguments with the arguments array.</b></span> <a name="1231646" id="1231646"></a> <span class="sansserif">You can refer to a function's arguments within the function by using the <span class="mono">arguments</span> array. See <a href="function.html#1193312">arguments</a>.</span>
      </p>
      <p>
        <a name="1205610" id="1205610"></a> <span class="sansserif"><b>Specifying arguments with the Function constructor.</b></span> <a name="1205611" id="1205611"></a> <span class="sansserif">The following code creates a <span class="mono">Function</span> object that takes two arguments.</span>
      </p>
      <p>
        <a name="1205612" id="1205612"></a><span class="mono">var multiply = new Function("x", "y", "return x * y")</span>
      </p>
      <p>
        <a name="1207137" id="1207137"></a> <span class="sansserif">The arguments <span class="mono">"x"</span> and <span class="mono">"y"</span> are formal argument names that are used in the function body, <span class="mono">"return x * y"</span>.</span>
      </p>
      <p>
        <a name="1207331" id="1207331"></a> <span class="sansserif">The preceding code assigns a function to the variable <span class="mono">multiply</span>. To call the <span class="mono">Function</span> object, you can specify the variable name as if it were a function, as shown in the following examples.</span>
      </p>
      <p>
        <a name="1207574" id="1207574"></a><span class="mono">var theAnswer = multiply(7,6)</span>
      </p>
      <p>
        <a name="1207332" id="1207332"></a><span class="mono">var myAge = 50<br>
         if (myAge &gt;=39) {myAge=multiply (myAge,.5)}</span>
      </p>
      <p>
        <a name="1224456" id="1224456"></a> <span class="sansserif"><b>Assigning a function to a variable with the Function constructor.</b></span> <a name="1224457" id="1224457"></a> <span class="sansserif">Suppose you create the variable <span class="mono">multiply</span> using the <span class="mono">Function</span> constructor, as shown in the preceding section:</span>
      </p>
      <p>
        <a name="1217471" id="1217471"></a><span class="mono">var multiply = new Function("x", "y", "return x * y")</span>
      </p>
      <p>
        <a name="1217469" id="1217469"></a> <span class="sansserif">This is similar to declaring the following function:</span>
      </p>
      <p>
        <a name="1206153" id="1206153"></a> <span class="mono">function multiply(x,y) {<br>
         &nbsp;&nbsp;&nbsp;return x*y<br>
         }</span>
      </p>
      <p>
        <a name="1193268" id="1193268"></a> <span class="sansserif">Assigning a function to a variable using the <span class="mono">Function</span> constructor is similar to declaring a function with the <span class="mono">function</span> statement, but they have differences:</span>
      </p>
      <ul>
        <li class="nobullet">
          <a name="1193269" id="1193269"></a>
        </li>
        <li>
          <span class="sansserif">When you assign a function to a variable using <span class="mono">var multiply = new Function("...")</span>, <span class="mono">multiply</span> is a variable for which the current value is a reference to the function created with <span class="mono">new Function()</span>.</span> 
          <p>
            <a name="1193270" id="1193270"></a>
          </p>
        </li>
        <li>
          When you create a function using <span class="mono">function multiply() {...}</span>, <span class="mono">multiply</span> is not a variable, it is the name of a function.
        </li>
      </ul>
      <p>
        <a name="1225385" id="1225385"></a> <span class="sansserif"><b>Nesting functions.</b></span> <a name="1225386" id="1225386"></a> <span class="sansserif">You can nest a function within a function. The nested (inner) function is private to its containing (outer) function:</span>
      </p>
      <ul>
        <li class="nobullet">
          <a name="1226496" id="1226496"></a>
        </li>
        <li>
          <span class="sansserif">The inner function can be accessed only from statements in the outer function.</span> 
          <p>
            <a name="1225764" id="1225764"></a>
          </p>
        </li>
        <li>
          The inner function can use the arguments and variables of the outer function. The outer function cannot use the arguments and variables of the inner function.
        </li>
      </ul><a name="1226522" id="1226522"></a> <span class="sansserif">The following example shows nested functions:</span> 
      <p>
        <a name="1227746" id="1227746"></a> <span class="mono">function addSquares (a,b) {<br>
         &nbsp;&nbsp;&nbsp;function square(x) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return x*x<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;return square(a) + square(b)<br>
         }<br>
         a=addSquares(2,3) // returns 13<br>
         b=addSquares(3,4) // returns 25<br>
         c=addSquares(4,5) // returns 41</span>
      </p>
      <p>
        <a name="1226900" id="1226900"></a> <span class="sansserif">When a function contains a nested function, you can call the outer function and specify arguments for both the outer and inner function:</span>
      </p>
      <p>
        <a name="1226901" id="1226901"></a> <span class="mono">function outside(x) {<br>
         &nbsp;&nbsp;&nbsp;function inside(y) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return x+y<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;return inside<br>
         }<br>
         result=outside(3)(5) // returns 8</span>
      </p>
      <p>
        <a name="1237524" id="1237524"></a> <span class="sansserif"><b>Specifying an event handler with a Function object.</b></span> <a name="1237525" id="1237525"></a> <span class="sansserif">The following code assigns a function to a window's <a class="mono" href="">onFocus</a> event handler (the event handler must be spelled in all lowercase):</span>
      </p>
      <p>
        <a name="1237529" id="1237529"></a> <span class="mono">window.onfocus = new Function("document.bgColor='antiquewhite'")</span>
      </p>
      <p>
        <a name="1237530" id="1237530"></a> <span class="sansserif">If a function is assigned to a variable, you can assign the variable to an event handler. The following code assigns a function to the variable <span class="mono">setBGColor</span>.</span>
      </p>
      <p>
        <a name="1237531" id="1237531"></a><span class="mono">var setBGColor = new Function("document.bgColor='antiquewhite'")</span>
      </p>
      <p>
        <a name="1237532" id="1237532"></a> <span class="sansserif">You can use this variable to assign a function to an event handler in either of the following ways:</span>
      </p>
      <p>
        <a name="1237533" id="1237533"></a> <span class="mono">document.form1.colorButton.onclick=setBGColor</span>
      </p>
      <p>
        <a name="1237534" id="1237534"></a> <span class="mono">&lt;INPUT NAME="colorButton" TYPE="button"<br>
         &nbsp;&nbsp;&nbsp;VALUE="Change background color"<br>
         &nbsp;&nbsp;&nbsp;onClick="setBGColor()"&gt;</span>
      </p>
      <p>
        <a name="1237535" id="1237535"></a> <span class="sansserif">Once you have a reference to a <span class="mono">Function</span> object, you can use it like a function and it will convert from an object to a function:</span>
      </p>
      <p>
        <a name="1237536" id="1237536"></a> <span class="mono">window.onfocus()</span>
      </p>
      <p>
        <a name="1237537" id="1237537"></a> <span class="sansserif">Event handlers do not take arguments, so you cannot declare any arguments in a <span class="mono">Function</span> constructor for an event handler. For example, you cannot call the function <span class="mono">multiply</span> by setting a button's <span class="mono">onclick</span> property as follows:</span>
      </p>
      <p>
        <a name="1237538" id="1237538"></a> <span class="mono">document.form1.button1.onclick=multFun(5,10)</span>
      </p>
      <p>
        <br>
         <a name="1216173" id="1216173"></a> <a name="Backward Compatibility" id="Backward Compatibility"></a> <span class="sansserif"><b>Backward Compatibility</b></span>
      </p>
      <p>
        <a name="1225182" id="1225182"></a> <span class="sansserif"><b>JavaScript 1.1 and earlier versions.</b></span> <a name="1225160" id="1225160"></a> <span class="sansserif">You cannot nest a function statement in another statement or in itself.</span>
      </p>
      <p>
        <br>
         <a name="1203656" id="1203656"></a> <a name="Property Summary" id="Property Summary"></a> <span class="sansserif"><b>Property Summary</b></span><br>
         <a name="1203704" id="1203704"></a> <span class="sansserif"><br></span>
      </p><br>
       
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr bgcolor="#CCCCCC" align="left" valign="top">
          <th valign="top" align="left">
            <a name="1203659" id="1203659"></a> 
            <p class="alignleft">
              <span class="sansserif"><b>Property</b></span>
            </p>
          </th>
          <th valign="top" align="left">
            <a name="1203661" id="1203661"></a> 
            <p class="alignleft">
              <span class="sansserif"><b>Description</b></span>
            </p>
          </th>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203666" id="1203666"></a> <span class="mono"><a href="function.html#1193312">arguments</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203668" id="1203668"></a> <span class="sansserif">An array corresponding to the arguments passed to a function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203673" id="1203673"></a> <span class="mono"><a href="function.html#1196419">arguments.callee</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203675" id="1203675"></a> <span class="sansserif">Specifies the function body of the currently executing function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203680" id="1203680"></a> <span class="mono"><a href="function.html#1196447">arguments.caller</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203682" id="1203682"></a> <span class="sansserif">Specifies the name of the function that invoked the currently executing function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203687" id="1203687"></a> <span class="mono"><a href="function.html#1196484">arguments.length</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203689" id="1203689"></a> <span class="sansserif">Specifies the number of arguments passed to the function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203694" id="1203694"></a> <span class="mono"><a href="function.html#1231596">arity</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203696" id="1203696"></a> <span class="sansserif">Specifies the number of arguments expected by the function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1204673" id="1204673"></a> <span class="mono"><a href="function.html#1204601">constructor</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1204675" id="1204675"></a> <span class="sansserif">Specifies the function that creates an object's prototype.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1217139" id="1217139"></a> <span class="mono"><a href="function.html#1216661">length</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1217141" id="1217141"></a> <span class="sansserif">Specifies the number of arguments expected by the function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203701" id="1203701"></a> <span class="mono"><a href="function.html#1193426">prototype</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203703" id="1203703"></a> <span class="sansserif">Allows the addition of properties to a <span class="mono">Function</span> object.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1203709" id="1203709"></a> <a name="Method Summary" id="Method Summary"></a> <span class="sansserif"><b>Method Summary</b></span><br>
         <a name="1203759" id="1203759"></a> <span class="sansserif"><br></span>
      </p><br>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr bgcolor="#CCCCCC" align="left" valign="top">
          <th valign="top" align="left">
            <a name="1203712" id="1203712"></a> 
            <p class="alignleft">
              <span class="sansserif"><b>Method</b></span>
            </p>
          </th>
          <th valign="top" align="left">
            <a name="1203714" id="1203714"></a> 
            <p class="alignleft">
              <span class="sansserif"><b>Description</b></span>
            </p>
          </th>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203719" id="1203719"></a> <span class="mono"><a href="function.html#1194017">apply</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203721" id="1203721"></a> <span class="sansserif">Allows you to apply a method of another object in the context of a different object (the calling object).</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203726" id="1203726"></a> <span class="mono"><a href="function.html#1194243">call</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203728" id="1203728"></a> <span class="sansserif">Allows you to call (execute) a method of another object in the context of a different object (the calling object).</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203733" id="1203733"></a> <span class="mono"><a href="function.html#1193583">toSource</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203735" id="1203735"></a> <span class="sansserif">Returns a string representing the source code of the function. Overrides the <a href="object.html#1193320">Object.toSource</a> method.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203743" id="1203743"></a> <span class="mono"><a href="function.html#1193615">toString</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203745" id="1203745"></a> <span class="sansserif">Returns a string representing the source code of the function. Overrides the <a href="object.html#1193350">Object.toString</a> method.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1203753" id="1203753"></a> <span class="mono"><a href="function.html#1199980">valueOf</a></span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1203755" id="1203755"></a> <span class="sansserif">Returns a string representing the source code of the function. Overrides the <a href="object.html#1193540">Object.valueOf</a> method.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1220053" id="1220053"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
         <a name="1220635" id="1220635"></a> <span class="sansserif"><b>Example 1.</b> The following function returns a string containing the formatted representation of a number padded with leading zeros.</span>
      </p>
      <p>
        <a name="1227379" id="1227379"></a><span class="mono">// This function returns a string padded with leading zeros<br>
         function padZeros(num, totalLen) {<br>
         &nbsp;&nbsp;&nbsp;var numStr = num.toString()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Initialize return value<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// as string<br>
         &nbsp;&nbsp;&nbsp;var numZeros = totalLen - numStr.length // Calculate no. of zeros<br>
         &nbsp;&nbsp;&nbsp;if (numZeros &gt; 0) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 1; i &lt;= numZeros; i++) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numStr = "0" + numStr<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;return numStr<br>
         }</span>
      </p>
      <p>
        <a name="1220892" id="1220892"></a> <span class="sansserif">The following statements call the <span class="mono">padZeros</span> function.</span>
      </p>
      <p>
        <a name="1220942" id="1220942"></a> <span class="mono">result=padZeros(42,4) // returns "0042"<br>
         result=padZeros(42,2) // returns "42"<br>
         result=padZeros(5,4)&nbsp; // returns "0005"</span>
      </p>
      <p>
        <a name="1237543" id="1237543"></a> <span class="sansserif"><b>Example 2.</b> You can determine whether a function exists by comparing the function name to null. In the following example, <span class="mono">func1</span> is called if the function <span class="mono">noFunc</span> does not exist; otherwise <span class="mono">func2</span> is called. Notice that the window name is needed when referring to the function name <span class="mono">noFunc</span>.</span>
      </p>
      <p>
        <a name="1237544" id="1237544"></a><span class="mono">if (window.noFunc == null)<br>
         &nbsp;&nbsp;&nbsp;func1()<br>
         else func2()</span>
      </p>
      <p>
        <a name="1237551" id="1237551"></a> <span class="sansserif"><b>Example 3.</b> The following example creates <a class="mono" href="">onFocus</a> and <a class="mono" href="">onBlur</a> event handlers for a frame. This code exists in the same file that contains the <span class="mono">FRAMESET</span> tag. Note that this is the only way to create <a class="mono" href="">onFocus</a> and <a class="mono" href="">onBlur</a> event handlers for a frame, because you cannot specify the event handlers in the <span class="mono">FRAME</span> tag.</span>
      </p>
      <p>
        <a name="1237558" id="1237558"></a> <span class="mono">frames[0].onfocus = new Function("document.bgColor='antiquewhite'")<br>
         frames[0].onblur = new Function("document.bgColor='lightgrey'")</span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1194017" id="1194017"></a> <a name="apply" id="apply"></a> <span class="sansserif"><b>apply</b></span>
      </p>
      <p>
        <a name="1237563" id="1237563"></a> <span class="sansserif">This feature is not in the ECMA specification that corresponds to JavaScript 1.3, but is expected in the next version.</span>
      </p>
      <p>
        <a name="1194019" id="1194019"></a> <span class="sansserif">Allows you to apply a method of another object in the context of a different object (the calling object).<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1196931" id="1196931"></a> <span class="sansserif"><i>Method of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196936" id="1196936"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196938" id="1196938"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196940" id="1196940"></a> <span class="sansserif">JavaScript 1.3</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1194032" id="1194032"></a> <a name="Syntax" id="Syntax"></a> <span class="sansserif"><b>Syntax</b></span><br>
         <a name="1194033" id="1194033"></a> <span class="mono">apply(<i>thisArg</i>[, <i>argArray</i>])</span>
      </p>
      <p>
        <br>
         <a name="1194034" id="1194034"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1194044" id="1194044"></a> <span class="sansserif"><br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <a name="1194037" id="1194037"></a> <span class="mono">thisArg</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1194039" id="1194039"></a> <span class="sansserif">Parameter for the calling object</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1194041" id="1194041"></a> <span class="mono">argArray</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1194043" id="1194043"></a> <span class="sansserif">An argument array for the object</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1194045" id="1194045"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1194046" id="1194046"></a> <span class="sansserif">You can assign a different <span class="mono">this</span> object when calling an existing function. <span class="mono">this</span> refers to the current object, the calling object. With <span class="mono">apply</span>, you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.</span>
      </p>
      <p>
        <a name="1194047" id="1194047"></a> <span class="sansserif"><span class="mono">apply</span> is very similar to <span class="mono">call</span>, except for the type of arguments it supports. You can use an arguments array instead of a named set of parameters. With <span class="mono">apply</span>, you can use an array literal, for example, <span class="mono">apply(this, [name, value])</span>, or an <span class="mono">Array</span> object, for example, <span class="mono">apply(this, new Array(name, value))</span>.</span>
      </p>
      <p>
        <a name="1209502" id="1209502"></a> <span class="sansserif">You can also use <a href="function.html#1193312">arguments</a> for the <span class="mono">argArray</span> parameter. <span class="mono">arguments</span> is a local variable of a function. It can be used for all unspecified arguments of the called object. Thus, you do not have to know the arguments of the called object when you use the <span class="mono">apply</span> method. You can use <span class="mono">arguments</span> to pass all the arguments to the called object. The called object is then responsible for handling the arguments.</span>
      </p>
      <p>
        <br>
         <a name="1194049" id="1194049"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
         <a name="1194050" id="1194050"></a> <span class="sansserif">You can use <span class="mono">apply</span> to chain constructors for an object, similar to Java. In the following example, the constructor for the <span class="mono">product</span> object is defined with two parameters, <span class="mono">name</span> and <span class="mono">value</span>. Another object, <span class="mono">prod_dept</span>, initializes its unique variable (<span class="mono">dept</span>) and calls the constructor for <span class="mono">product</span> in its constructor to initialize the other variables. In this example, the parameter <span class="mono">arguments</span> is used for all arguments of the <span class="mono">product</span> object's constructor.</span>
      </p>
      <p>
        <a name="1194051" id="1194051"></a> <span class="mono">function product(name, value){<br>
         &nbsp;&nbsp;&nbsp;this.name = name;<br>
         &nbsp;&nbsp;&nbsp;if(value &gt; 1000)<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value = 999;<br>
         &nbsp;&nbsp;&nbsp;else<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value = value;<br>
         }</span>
      </p>
      <p>
        <a name="1194052" id="1194052"></a> <span class="mono">function prod_dept(name, value, dept){<br>
         &nbsp;&nbsp;&nbsp;this.dept = dept;<br>
         &nbsp;&nbsp;&nbsp;product.apply(product, arguments);<br>
         }</span>
      </p>
      <p>
        <a name="1194053" id="1194053"></a> <span class="mono">prod_dept.prototype = new product();</span>
      </p>
      <p>
        <a name="1194054" id="1194054"></a><span class="mono">// since 5 is less than 100 value is set<br>
         cheese = new prod_dept("feta", 5, "food");</span>
      </p>
      <p>
        <a name="1194055" id="1194055"></a><span class="mono">// since 5000 is above 1000, value will be 999<br>
         car = new prod_dept("honda", 5000, "auto");</span>
      </p>
      <p>
        <br>
         <a name="1194056" id="1194056"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1194060" id="1194060"></a> <span class="sansserif"><a href="function.html#1194243">Function.call</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1193312" id="1193312"></a> <a name="arguments" id="arguments"></a> <span class="sansserif"><b>arguments</b></span>
      </p>
      <p>
        <a name="1193325" id="1193325"></a> <span class="sansserif">An array corresponding to the arguments passed to a function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1228902" id="1228902"></a> <span class="sansserif"><i>Local variable of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1228907" id="1228907"></a> <span class="sansserif">All function objects</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193315" id="1193315"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193320" id="1193320"></a> <span class="sansserif"><a href="function.html#1193137">Function</a> (deprecated)</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193322" id="1193322"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193324" id="1193324"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span>
            </p>
            <p>
              <a name="1194829" id="1194829"></a>
            </p>
            <p>
              <a name="1194830" id="1194830"></a> <span class="sansserif">JavaScript 1.2: added <a href="function.html#1196419">arguments.callee</a> property.</span>
            </p>
            <p>
              <a name="1210050" id="1210050"></a>
            </p>
            <p>
              <a name="1212031" id="1212031"></a> <span class="sansserif">JavaScript 1.3: deprecated <a href="function.html#1196447">arguments.caller</a> property; removed support for argument names and local variable names as properties of the <span class="mono">arguments</span> array.</span>
            </p>
            <p>
              <a name="1212032" id="1212032"></a>
            </p>
            <p>
              <a name="1210081" id="1210081"></a> <span class="sansserif">JavaScript 1.4: deprecated <span class="mono">arguments</span>, <a href="function.html#1196419">arguments.callee</a>, and <a href="function.html#1196484">arguments.length</a> as properties of <span class="mono">Function</span>; retained <span class="mono">arguments</span> as a local variable of a function and <a href="function.html#1196419">arguments.callee</a> and <a href="function.html#1196484">arguments.length</a> as properties of this variable.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196948" id="1196948"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196950" id="1196950"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1211023" id="1211023"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1230788" id="1230788"></a> <span class="sansserif">The <span class="mono">arguments</span> array is a local variable available within all function objects; <span class="mono">arguments</span> as a property of <span class="mono">Function</span> is no longer used.</span>
      </p>
      <p>
        <a name="1229024" id="1229024"></a> <span class="sansserif">You can refer to a function's arguments within the function by using the <span class="mono">arguments</span> array. This array contains an entry for each argument passed to the function. For example, if a function is passed three arguments, you can refer to the arguments as follows:</span>
      </p>
      <p>
        <a name="1229025" id="1229025"></a> <span class="mono">arguments[0]<br>
         arguments[1]<br>
         arguments[2]</span>
      </p>
      <p>
        <a name="1229074" id="1229074"></a> <span class="sansserif">The <span class="mono">arguments</span> array is available only within a function body. Attempting to access the <span class="mono">arguments</span> array outside a function declaration results in an error.</span>
      </p>
      <p>
        <a name="1229290" id="1229290"></a> <span class="sansserif">You can use the <span class="mono">arguments</span> array if you call a function with more arguments than it is formally declared to accept. This technique is useful for functions that can be passed a variable number of arguments. You can use <span class="mono">arguments.length</span> to determine the number of arguments passed to the function, and then process each argument by using the <span class="mono">arguments</span> array. (To determine the number of arguments declared when a function was defined, use the <a href="function.html#1216661">Function.length</a> property.)</span>
      </p>
      <p>
        <a name="1193330" id="1193330"></a> <span class="sansserif">The <span class="mono">arguments</span> array has the following properties:</span>
      </p>
      <p>
        <a name="1211223" id="1211223"></a> <span class="sansserif"><br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr bgcolor="#CCCCCC" align="left" valign="top">
          <th valign="top" align="left">
            <a name="1211170" id="1211170"></a> 
            <p class="alignleft">
              <span class="sansserif"><b>Property</b></span>
            </p>
          </th>
          <th valign="top" align="left">
            <a name="1211172" id="1211172"></a> 
            <p class="alignleft">
              <span class="sansserif"><b>Description</b></span>
            </p>
          </th>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1211177" id="1211177"></a> <span class="sansserif"><a href="function.html#1196419">arguments.callee</a></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1211179" id="1211179"></a> <span class="sansserif">Specifies the function body of the currently executing function.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1211184" id="1211184"></a> <span class="sansserif"><a href="function.html#1196447">arguments.caller</a></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1211186" id="1211186"></a> <span class="sansserif">Specifies the name of the function that invoked the currently executing function. (Deprecated)</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1211191" id="1211191"></a> <span class="sansserif"><a href="function.html#1196484">arguments.length</a></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1211193" id="1211193"></a> <span class="sansserif">Specifies the number of arguments passed to the function.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1211676" id="1211676"></a> <a name="Backward Compatibility" id="Backward Compatibility"></a> <span class="sansserif"><b>Backward Compatibility</b></span><br>
      </p>
      <p>
        <a name="1228978" id="1228978"></a> <span class="sansserif"><b>JavaScript 1.3 and earlier versions.</b></span> <a name="1228979" id="1228979"></a> <span class="sansserif">In addition to being available as a local variable, the <span class="mono">arguments</span> array is also a property of the <span class="mono">Function</span> object and can be preceded by the function name. For example, if a function <span class="mono">myFunc</span> is passed three arguments named <span class="mono">arg1</span>, <span class="mono">arg2</span>, and <span class="mono">arg3</span>, you can refer to the arguments as follows:</span>
      </p>
      <p>
        <a name="1229046" id="1229046"></a> <span class="mono">myFunc.arguments[0]<br>
         myFunc.arguments[1]<br>
         myFunc.arguments[2]</span>
      </p>
      <p>
        <a name="1211677" id="1211677"></a> <span class="sansserif"><b>JavaScript 1.1 and 1.2.</b></span> <a name="1212477" id="1212477"></a> <span class="sansserif">The following features, which were available in JavaScript&nbsp;1.1 and JavaScript&nbsp;1.2, have been removed:</span>
      </p>
      <ul>
        <li class="nobullet">
          <a name="1214329" id="1214329"></a>
        </li>
        <li>
          <span class="sansserif">Each local variable of a function is a property of the <span class="mono">arguments</span> array. For example, if a function <span class="mono">myFunc</span> has a local variable named <span class="mono">myLocalVar</span>, you can refer to the variable as <span class="mono">arguments.myLocalVar</span>.</span> 
          <p>
            <a name="1211678" id="1211678"></a>
          </p>
        </li>
        <li>
          Each formal argument of a function is a property of the <span class="mono">arguments</span> array. For example, if a function <span class="mono">myFunc</span> has two arguments named <span class="mono">arg1</span> and <span class="mono">arg2</span>, you can refer to the arguments as <span class="mono">arguments.arg1</span> and <span class="mono">arguments.arg2</span>. (You can also refer to them as <span class="mono">arguments[0]</span> and <span class="mono">arguments[1]</span>.)
        </li>
      </ul><br>
       <a name="1211592" id="1211592"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
       <a name="1229844" id="1229844"></a> <span class="sansserif"><b>Example 1.</b> This example defines a function that concatenates several strings. The only formal argument for the function is a string that specifies the characters that separate the items to concatenate. The function is defined as follows:</span> 
      <p>
        <a name="1229845" id="1229845"></a> <span class="mono">function myConcat(separator) {<br>
         &nbsp;&nbsp;&nbsp;result="" // initialize list<br>
         &nbsp;&nbsp;&nbsp;// iterate through arguments<br>
         &nbsp;&nbsp;&nbsp;for (var i=1; i&lt;arguments.length; i++) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result += arguments[i] + separator<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;return result<br>
         }</span>
      </p>
      <p>
        <a name="1229846" id="1229846"></a> <span class="sansserif">You can pass any number of arguments to this function, and it creates a list using each argument as an item in the list.</span>
      </p>
      <p>
        <a name="1229847" id="1229847"></a><span class="mono">// returns "red, orange, blue, "<br>
         myConcat(", ","red","orange","blue")</span>
      </p>
      <p>
        <a name="1229848" id="1229848"></a><span class="mono">// returns "elephant; giraffe; lion; cheetah;"<br>
         myConcat("; ","elephant","giraffe","lion", "cheetah")</span>
      </p>
      <p>
        <a name="1229849" id="1229849"></a><span class="mono">// returns "sage. basil. oregano. pepper. parsley. "<br>
         myConcat(". ","sage","basil","oregano", "pepper", "parsley")</span>
      </p>
      <p>
        <a name="1237568" id="1237568"></a> <span class="sansserif"><b>Example 2.</b> This example defines a function that creates HTML lists. The only formal argument for the function is a string that is <span class="mono">"U"</span> if the list is to be unordered (bulleted), or <span class="mono">"O"</span> if the list is to be ordered (numbered). The function is defined as follows:</span>
      </p>
      <p>
        <a name="1237569" id="1237569"></a> <span class="mono">function list(type) {<br>
         &nbsp;&nbsp;&nbsp;document.write("&lt;" + type + "L&gt;") // begin list<br>
         &nbsp;&nbsp;&nbsp;// iterate through arguments<br>
         &nbsp;&nbsp;&nbsp;for (var i=1; i&lt;arguments.length; i++) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.write("&lt;LI&gt;" + arguments[i])<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;document.write("&lt;/" + type + "L&gt;") // end list<br>
         }</span>
      </p>
      <p>
        <a name="1237570" id="1237570"></a> <span class="sansserif">You can pass any number of arguments to this function, and it displays each argument as an item in the type of list indicated. For example, the following call to the function</span>
      </p>
      <p>
        <a name="1237571" id="1237571"></a> <span class="mono">list("U", "One", "Two", "Three")</span>
      </p>
      <p>
        <a name="1237572" id="1237572"></a> <span class="sansserif">results in this output:</span>
      </p>
      <p>
        <a name="1237573" id="1237573"></a> <span class="mono">&lt;UL&gt;<br>
         &lt;LI&gt;One<br>
         &lt;LI&gt;Two<br>
         &lt;LI&gt;Three<br>
         &lt;/UL&gt;</span>
      </p>
      <p>
        <a name="1237577" id="1237577"></a> <span class="sansserif">In server-side JavaScript, you can display the same output by calling the <a class="mono" href="toplev.html#15484">write</a> function instead of using <span class="mono">document.write</span>.</span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1196419" id="1196419"></a> <a name="arguments.callee" id="arguments.callee"></a> <span class="sansserif"><b>arguments.callee</b></span>
      </p>
      <p>
        <a name="1196433" id="1196433"></a> <span class="sansserif">Specifies the function body of the currently executing function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1230356" id="1230356"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1230361" id="1230361"></a> <span class="sansserif"><a href="function.html#1193312">arguments</a> local variable; <a href="function.html#1193137">Function</a> (deprecated)</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196429" id="1196429"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196431" id="1196431"></a> <span class="sansserif">JavaScript 1.2</span>
            </p>
            <p>
              <a name="1216461" id="1216461"></a>
            </p>
            <p>
              <a name="1196432" id="1196432"></a> <span class="sansserif">JavaScript 1.4: Deprecated <span class="mono">callee</span> as a property of <span class="mono">Function.arguments</span>, retained it as a property of a function's local <span class="mono">arguments</span> variable.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196953" id="1196953"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196955" id="1196955"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1196434" id="1196434"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1230831" id="1230831"></a> <span class="sansserif"><span class="mono">arguments.callee</span> is a property of the <a href="function.html#1193312">arguments</a> local variable available within all function objects; <span class="mono">arguments.callee</span> as a property of <span class="mono">Function</span> is no longer used.</span>
      </p>
      <p>
        <a name="1196435" id="1196435"></a> <span class="sansserif">The <span class="mono">callee</span> property is available only within the body of a function.</span>
      </p>
      <p>
        <a name="1196436" id="1196436"></a> <span class="sansserif">The <span class="mono">this</span> keyword does not refer to the currently executing function. Use the <span class="mono">callee</span> property to refer to a function within the function body.</span>
      </p>
      <p>
        <br>
         <a name="1196437" id="1196437"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
         <a name="1196438" id="1196438"></a> <span class="sansserif">The following function returns the value of the function's <span class="mono">callee</span> property.</span>
      </p>
      <p>
        <a name="1227944" id="1227944"></a> <span class="mono">function myFunc() {<br>
         &nbsp;&nbsp;&nbsp;return arguments.callee<br>
         }</span>
      </p>
      <p>
        <a name="1218821" id="1218821"></a> <span class="sansserif">The following value is returned:</span>
      </p>
      <p>
        <a name="1218822" id="1218822"></a> <span class="mono">function myFunc() { return arguments.callee; }</span>
      </p>
      <p>
        <br>
         <a name="1196440" id="1196440"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1196444" id="1196444"></a> <span class="sansserif"><a href="function.html#1193312">Function.arguments</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1196447" id="1196447"></a> <a name="arguments.caller" id="arguments.caller"></a> <span class="sansserif"><b>arguments.caller</b></span>
      </p>
      <p>
        <a name="1196462" id="1196462"></a> <span class="sansserif">Specifies the name of the function that invoked the currently executing function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1196450" id="1196450"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196455" id="1196455"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196457" id="1196457"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196459" id="1196459"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span>
            </p>
            <p>
              <a name="1196460" id="1196460"></a>
            </p>
            <p>
              <a name="1196461" id="1196461"></a> <span class="sansserif">Deprecated in JavaScript 1.3</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1196463" id="1196463"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1196467" id="1196467"></a> <span class="sansserif"><span class="mono">caller</span> is no longer used.</span>
      </p>
      <p>
        <a name="1196468" id="1196468"></a> <span class="sansserif">The <span class="mono">caller</span> property is available only within the body of a function.</span>
      </p>
      <p>
        <a name="1196469" id="1196469"></a> <span class="sansserif">If the currently executing function was invoked by the top level of a JavaScript program, the value of <span class="mono">caller</span> is null.</span>
      </p>
      <p>
        <a name="1196470" id="1196470"></a> <span class="sansserif">The <span class="mono">this</span> keyword does not refer to the currently executing function, so you must refer to functions and <span class="mono">Function</span> objects by name, even within the function body.</span>
      </p>
      <p>
        <a name="1196471" id="1196471"></a> <span class="sansserif">The <span class="mono">caller</span> property is a reference to the calling function, so</span>
      </p>
      <ul>
        <li class="nobullet">
          <a name="1196472" id="1196472"></a>
        </li>
        <li>
          <span class="sansserif">If you use it in a string context, you get the result of calling <span class="mono">functionName.toString</span>. That is, the decompiled canonical source form of the function.</span> 
          <p>
            <a name="1196473" id="1196473"></a>
          </p>
        </li>
        <li>
          You can also call the calling function, if you know what arguments it might want. Thus, a called function can call its caller without knowing the name of the particular caller, provided it knows that all of its callers have the same form and fit, and that they will not call the called function again unconditionally (which would result in infinite recursion).
        </li>
      </ul><br>
       <a name="1196474" id="1196474"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
       <a name="1196475" id="1196475"></a> <span class="sansserif">The following code checks the value of a function's <span class="mono">caller</span> property.</span> 
      <p>
        <a name="1196476" id="1196476"></a> <span class="mono">function myFunc() {<br>
         &nbsp;&nbsp;&nbsp;if (arguments.caller == null) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ("The function was called from the top!")<br>
         &nbsp;&nbsp;&nbsp;} else return ("This function's caller was " + arguments.caller)<br>
         }</span>
      </p>
      <p>
        <br>
         <a name="1196477" id="1196477"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1196481" id="1196481"></a> <span class="sansserif"><a href="function.html#1193312">Function.arguments</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1196484" id="1196484"></a> <a name="arguments.length" id="arguments.length"></a> <span class="sansserif"><b>arguments.length</b></span>
      </p>
      <p>
        <a name="1196497" id="1196497"></a> <span class="sansserif">Specifies the number of arguments passed to the function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1196487" id="1196487"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196492" id="1196492"></a> <span class="sansserif"><a href="function.html#1193312">arguments</a> local variable; <a href="function.html#1193137">Function</a> (deprecated)</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196494" id="1196494"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1216487" id="1216487"></a> <span class="sansserif">JavaScript 1.1</span>
            </p>
            <p>
              <a name="1216488" id="1216488"></a>
            </p>
            <p>
              <a name="1196496" id="1196496"></a> <span class="sansserif">JavaScript 1.4: Deprecated <span class="mono">length</span> as a property of <span class="mono">Function.arguments</span>, retained it as a property of a function's local <span class="mono">arguments</span> variable.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1196993" id="1196993"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1196995" id="1196995"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1196498" id="1196498"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1231270" id="1231270"></a> <span class="sansserif"><span class="mono">arguments.length</span> is a property of the <a href="function.html#1193312">arguments</a> local variable available within all function objects; <span class="mono">arguments.length</span> as a property of <span class="mono">Function</span> is no longer used.</span>
      </p>
      <p>
        <a name="1224928" id="1224928"></a> <span class="sansserif"><span class="mono">arguments.length</span> provides the number of arguments actually passed to a function. By contrast, the <a href="function.html#1216661">Function.length</a> property indicates how many arguments a function expects.</span>
      </p>
      <p>
        <br>
         <a name="1196500" id="1196500"></a> <a name="Example" id="Example"></a> <span class="sansserif"><b>Example</b></span><br>
         <a name="1217398" id="1217398"></a> <span class="sansserif">The following example demonstrates the use of <span class="mono">Function.length</span> and <span class="mono">arguments.length</span>.</span>
      </p>
      <p>
        <a name="1222915" id="1222915"></a> <span class="mono">function addNumbers(x,y){<br>
         &nbsp;&nbsp;&nbsp;if (arguments.length == addNumbers.length) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (x+y)<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;else return 0<br>
         }</span>
      </p>
      <p>
        <a name="1223278" id="1223278"></a> <span class="sansserif">If you pass more than two arguments to this function, the function returns 0:</span>
      </p>
      <p>
        <a name="1223239" id="1223239"></a> <span class="mono">result=addNumbers(3,4,5)&nbsp;&nbsp;&nbsp;// returns 0<br>
         result=addNumbers(3,4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns 7<br>
         result=addNumbers(103,104) // returns 207</span>
      </p>
      <p>
        <br>
         <a name="1231586" id="1231586"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1231593" id="1231593"></a> <span class="sansserif"><a href="function.html#1193312">Function.arguments</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1231596" id="1231596"></a> <a name="arity" id="arity"></a> <span class="sansserif"><b>arity</b></span>
      </p>
      <p>
        <a name="1193363" id="1193363"></a> <span class="sansserif">Specifies the number of arguments expected by the function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1193366" id="1193366"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193371" id="1193371"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193373" id="1193373"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193375" id="1193375"></a> <span class="sansserif">JavaScript 1.2, NES 3.0</span>
            </p>
            <p>
              <a name="1216652" id="1216652"></a>
            </p>
            <p>
              <a name="1216653" id="1216653"></a> <span class="sansserif">Deprecated in JavaScript 1.4.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193376" id="1193376"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1216608" id="1216608"></a> <span class="sansserif"><span class="mono">arity</span> is no longer used and has been replaced by the <a href="function.html#1216661">length</a> property.</span>
      </p>
      <p>
        <a name="1193377" id="1193377"></a> <span class="sansserif"><span class="mono">arity</span> is external to the function, and indicates how many arguments a function expects. By contrast, <a href="function.html#1196484">arguments.length</a> provides the number of arguments actually passed to a function.</span>
      </p>
      <p>
        <br>
         <a name="1193381" id="1193381"></a> <a name="Example" id="Example"></a> <span class="sansserif"><b>Example</b></span><br>
         <a name="1193382" id="1193382"></a> <span class="sansserif">The following example demonstrates the use of <span class="mono">arity</span> and <a href="function.html#1196484">arguments.length</a>.</span>
      </p>
      <p>
        <a name="1223785" id="1223785"></a> <span class="mono">function addNumbers(x,y){<br>
         &nbsp;&nbsp;&nbsp;if (arguments.length == addNumbers.length) {<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (x+y)<br>
         &nbsp;&nbsp;&nbsp;}<br>
         &nbsp;&nbsp;&nbsp;else return 0<br>
         }</span>
      </p>
      <p>
        <a name="1223786" id="1223786"></a> <span class="sansserif">If you pass more than two arguments to this function, the function returns 0:</span>
      </p>
      <p>
        <a name="1223787" id="1223787"></a> <span class="mono">result=addNumbers(3,4,5)&nbsp;&nbsp;&nbsp;// returns 0<br>
         result=addNumbers(3,4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns 7<br>
         result=addNumbers(103,104) // returns 207</span>
      </p>
      <p>
        <br>
         <a name="1196820" id="1196820"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1196827" id="1196827"></a> <span class="sansserif"><a href="function.html#1196484">arguments.length</a>, <a href="function.html#1216661">Function.length</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1194243" id="1194243"></a> <a name="call" id="call"></a> <span class="sansserif"><b>call</b></span>
      </p>
      <p>
        <a name="1237582" id="1237582"></a> <span class="sansserif">This feature is not in the ECMA specification that corresponds to JavaScript 1.3, but is expected in the next version.</span>
      </p>
      <p>
        <a name="1194245" id="1194245"></a> <span class="sansserif">Allows you to call (execute) a method of another object in the context of a different object (the calling object).<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1194248" id="1194248"></a> <span class="sansserif"><i>Method of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1194253" id="1194253"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1194255" id="1194255"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1194257" id="1194257"></a> <span class="sansserif">JavaScript 1.3</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1194258" id="1194258"></a> <a name="Syntax" id="Syntax"></a> <span class="sansserif"><b>Syntax</b></span><br>
         <a name="1194259" id="1194259"></a> <span class="mono">call(<i>thisArg</i>[, <i>arg1</i>[, <i>arg2</i>[, ...]]])</span>
      </p>
      <p>
        <br>
         <a name="1194260" id="1194260"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1194270" id="1194270"></a> <span class="sansserif"><br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <a name="1194263" id="1194263"></a> <span class="mono">thisArg</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1194265" id="1194265"></a> <span class="sansserif">Parameter for the calling object</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1194267" id="1194267"></a> <span class="mono">arg1, arg2, ...</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1194269" id="1194269"></a> <span class="sansserif">Arguments for the object</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1194271" id="1194271"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1194272" id="1194272"></a> <span class="sansserif">You can assign a different <span class="mono">this</span> object when calling an existing function. <span class="mono">this</span> refers to the current object, the calling object.</span>
      </p>
      <p>
        <a name="1194273" id="1194273"></a> <span class="sansserif">With <span class="mono">call</span>, you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.</span>
      </p>
      <p>
        <br>
         <a name="1194274" id="1194274"></a> <a name="Examples" id="Examples"></a> <span class="sansserif"><b>Examples</b></span><br>
         <a name="1194275" id="1194275"></a> <span class="sansserif">You can use <span class="mono">call</span> to chain constructors for an object, similar to Java. In the following example, the constructor for the <span class="mono">product</span> object is defined with two parameters, <span class="mono">name</span> and <span class="mono">value</span>. Another object, <span class="mono">prod_dept</span>, initializes its unique variable (<span class="mono">dept</span>) and calls the constructor for <span class="mono">product</span> in its constructor to initialize the other variables.</span>
      </p>
      <p>
        <a name="1194276" id="1194276"></a> <span class="mono">function product(name, value){<br>
         &nbsp;&nbsp;&nbsp;this.name = name;<br>
         &nbsp;&nbsp;&nbsp;if(value &gt; 1000)<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value = 999;<br>
         &nbsp;&nbsp;&nbsp;else<br>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value = value;<br>
         }</span>
      </p>
      <p>
        <a name="1194277" id="1194277"></a> <span class="mono">function prod_dept(name, value, dept){<br>
         &nbsp;&nbsp;&nbsp;this.dept = dept;<br>
         &nbsp;&nbsp;&nbsp;product.call(this, name, value);<br>
         }</span>
      </p>
      <p>
        <a name="1194278" id="1194278"></a> <span class="mono">prod_dept.prototype = new product();</span>
      </p>
      <p>
        <a name="1194279" id="1194279"></a><span class="mono">// since 5 is less than 100 value is set<br>
         cheese = new prod_dept("feta", 5, "food");</span>
      </p>
      <p>
        <a name="1194280" id="1194280"></a><span class="mono">// since 5000 is above 1000, value will be 999<br>
         car = new prod_dept("honda", 5000, "auto");</span>
      </p>
      <p>
        <br>
         <a name="1194281" id="1194281"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1194285" id="1194285"></a> <span class="sansserif"><a href="function.html#1194017">Function.apply</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1204601" id="1204601"></a> <a name="constructor" id="constructor"></a> <span class="sansserif"><b>constructor</b></span>
      </p>
      <p>
        <a name="1204602" id="1204602"></a> <span class="sansserif">Specifies the function that creates an object's prototype. Note that the value of this property is a reference to the function itself, not a string containing the function's name.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1204605" id="1204605"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1204610" id="1204610"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1204612" id="1204612"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1204614" id="1204614"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1204616" id="1204616"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1204618" id="1204618"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1204619" id="1204619"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1204623" id="1204623"></a> <span class="sansserif">See <a href="object.html#1193229">Object.constructor</a>.</span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1216661" id="1216661"></a> <a name="length" id="length"></a> <span class="sansserif"><b>length</b></span>
      </p>
      <p>
        <a name="1216677" id="1216677"></a> <span class="sansserif">Specifies the number of arguments expected by the function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1216665" id="1216665"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1216670" id="1216670"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1216672" id="1216672"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1216676" id="1216676"></a> <span class="sansserif">JavaScript 1.1</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1216885" id="1216885"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1216887" id="1216887"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1216678" id="1216678"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1216935" id="1216935"></a> <span class="sansserif"><span class="mono">length</span> is external to a function, and indicates how many arguments the function expects. By contrast, <span class="mono">arguments.length</span> is local to a function and provides the number of arguments actually passed to the function.</span>
      </p>
      <p>
        <br>
         <a name="1216688" id="1216688"></a> <a name="Example" id="Example"></a> <span class="sansserif"><b>Example</b></span><br>
         <a name="1216689" id="1216689"></a> <span class="sansserif">See the example for <a href="function.html#1196484">arguments.length</a>.</span>
      </p>
      <p>
        <br>
         <a name="1216696" id="1216696"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1216700" id="1216700"></a> <span class="sansserif"><a href="function.html#1196484">arguments.length</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1193426" id="1193426"></a> <a name="prototype" id="prototype"></a> <span class="sansserif"><b>prototype</b></span>
      </p>
      <p>
        <a name="1193427" id="1193427"></a> <span class="sansserif">A value from which instances of a particular class are created. Every object that can be created by calling a constructor function has an associated <span class="mono">prototype</span> property.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1193430" id="1193430"></a> <span class="sansserif"><i>Property of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193435" id="1193435"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193437" id="1193437"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193439" id="1193439"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1197004" id="1197004"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1197006" id="1197006"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193440" id="1193440"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1193441" id="1193441"></a> <span class="sansserif">You can add new properties or methods to an existing class by adding them to the prototype associated with the constructor function for that class. The syntax for adding a new property or method is:</span>
      </p>
      <p>
        <a name="1193442" id="1193442"></a> <span class="mono"><i>fun</i>.prototype.<i>name</i> = <i>value</i></span>
      </p>
      <p>
        <a name="1193456" id="1193456"></a> <span class="sansserif">where<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <a name="1193445" id="1193445"></a> <span class="mono">fun</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193447" id="1193447"></a> <span class="sansserif">The name of the constructor function object you want to change.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1193449" id="1193449"></a> <span class="mono">name</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193451" id="1193451"></a> <span class="sansserif">The name of the property or method to be created.</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <a name="1193453" id="1193453"></a> <span class="mono">value</span> 
            <p>
              &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193455" id="1193455"></a> <span class="sansserif">The value initially assigned to the new property or method.</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <a name="1193457" id="1193457"></a> <span class="sansserif">If you add a property to the prototype for an object, then all objects created with that object's constructor function will have that new property, even if the objects existed before you created the new property. For example, assume you have the following statements:</span>
      </p>
      <p>
        <a name="1193458" id="1193458"></a><span class="mono">var array1 = new Array();<br>
         var array2 = new Array(3);<br>
         Array.prototype.description=null;<br>
         array1.description="Contains some stuff"<br>
         array2.description="Contains other stuff"</span>
      </p>
      <p>
        <a name="1193459" id="1193459"></a> <span class="sansserif">After you set a property for the prototype, all subsequent objects created with <span class="mono">Array</span> will have the property:</span>
      </p>
      <p>
        <a name="1193460" id="1193460"></a> <span class="mono">anotherArray=new Array()<br>
         anotherArray.description="Currently empty"</span>
      </p>
      <p>
        <br>
         <a name="1193461" id="1193461"></a> <a name="Example" id="Example"></a> <span class="sansserif"><b>Example</b></span><br>
         <a name="1193462" id="1193462"></a> <span class="sansserif">The following example creates a method, <span class="mono">str_rep</span>, and uses the statement <span class="mono">String.prototype.rep = str_rep</span> to add the method to all <a href="string.html#1193137">String</a> objects. All objects created with <span class="mono">new String()</span> then have that method, even objects already created. The example then creates an alternate method and adds that to one of the <a href="string.html#1193137">String</a> objects using the statement <span class="mono">s1.rep = fake_rep</span>. The <span class="mono">str_rep</span> method of the remaining <a href="string.html#1193137">String</a> objects is not altered.</span>
      </p>
      <p>
        <a name="1223859" id="1223859"></a><span class="mono">var s1 = new String("a")<br>
         var s2 = new String("b")<br>
         var s3 = new String("c")</span>
      </p>
      <p>
        <a name="1223928" id="1223928"></a><span class="mono">// Create a repeat-string-N-times method for all String objects<br>
         function str_rep(n) {<br>
         &nbsp;&nbsp;&nbsp;var s = "", t = this.toString()<br>
         &nbsp;&nbsp;&nbsp;while (--n &gt;= 0) s += t<br>
         &nbsp;&nbsp;&nbsp;return s<br>
         }</span>
      </p>
      <p>
        <a name="1223869" id="1223869"></a> <span class="mono">String.prototype.rep = str_rep</span>
      </p>
      <p>
        <a name="1224082" id="1224082"></a> <span class="mono">s1a=s1.rep(3) // returns "aaa"<br>
         s2a=s2.rep(5) // returns "bbbbb"<br>
         s3a=s3.rep(2) // returns "cc"</span>
      </p>
      <p>
        <a name="1224239" id="1224239"></a><span class="mono">// Create an alternate method and assign it to only one String variable<br>
         function fake_rep(n) {<br>
         &nbsp;&nbsp;&nbsp;return "repeat " + this + " " + n + " times."<br>
         }</span>
      </p>
      <p>
        <a name="1223881" id="1223881"></a> <span class="mono">s1.rep = fake_rep<br>
         s1b=s1.rep(1) // returns "repeat a 1 times."<br>
         s2b=s2.rep(4) // returns "bbbb"<br>
         s3b=s3.rep(6) // returns "cccccc"</span>
      </p>
      <p>
        <a name="1193484" id="1193484"></a> <span class="sansserif">The function in this example also works on <a href="string.html#1193137">String</a> objects not created with the <a href="string.html#1193137">String</a> constructor. The following code returns <span class="mono">"zzz"</span>.</span>
      </p>
      <p>
        <a name="1193488" id="1193488"></a> <span class="mono">"z".rep(3)</span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1193583" id="1193583"></a> <a name="toSource" id="toSource"></a> <span class="sansserif"><b>toSource</b></span>
      </p>
      <p>
        <a name="1237587" id="1237587"></a> <span class="sansserif">This feature is not in the ECMA specification that corresponds to JavaScript 1.3, but is expected in the next version.</span>
      </p>
      <p>
        <a name="1193585" id="1193585"></a> <span class="sansserif">Returns a string representing the source code of the function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1193588" id="1193588"></a> <span class="sansserif"><i>Method of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193593" id="1193593"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193595" id="1193595"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193597" id="1193597"></a> <span class="sansserif">JavaScript 1.3</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193598" id="1193598"></a> <a name="Syntax" id="Syntax"></a> <span class="sansserif"><b>Syntax</b></span><br>
         <a name="1193599" id="1193599"></a> <span class="mono">toSource()</span>
      </p>
      <p>
        <br>
         <a name="1193600" id="1193600"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1193601" id="1193601"></a> <span class="sansserif">None</span>
      </p>
      <p>
        <br>
         <a name="1200271" id="1200271"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1231792" id="1231792"></a> <span class="sansserif">The <span class="mono">toSource</span> method returns the following values:</span>
      </p>
      <ul>
        <li class="nobullet">
          <a name="1231793" id="1231793"></a>
        </li>
        <li>
          <span class="sansserif">For the built-in <span class="mono">Function</span> object, <span class="mono">toSource</span> returns the following string indicating that the source code is not available:</span> 
          <p>
            <a name="1231794" id="1231794"></a> <span class="mono">&nbsp;&nbsp;&nbsp;function Function() {<br>
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[native code]<br>
             &nbsp;&nbsp;&nbsp;}</span>
          </p>
          <p>
            <a name="1231796" id="1231796"></a>
          </p>
        </li>
        <li>
          For custom functions, <span class="mono">toSource</span> returns the JavaScript source that defines the object as a string.
        </li>
      </ul><a name="1231797" id="1231797"></a> <span class="sansserif">This method is usually called internally by JavaScript and not explicitly in code. You can call toSource while debugging to examine the contents of an object.</span> 
      <p>
        <br>
         <a name="1200289" id="1200289"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1200296" id="1200296"></a> <span class="sansserif"><a href="function.html#1193615">Function.toString</a>, <a href="object.html#1193540">Object.valueOf</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1193615" id="1193615"></a> <a name="toString" id="toString"></a> <span class="sansserif"><b>toString</b></span>
      </p>
      <p>
        <a name="1193628" id="1193628"></a> <span class="sansserif">Returns a string representing the source code of the function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1193618" id="1193618"></a> <span class="sansserif"><i>Method of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193623" id="1193623"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1193625" id="1193625"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1193627" id="1193627"></a> <span class="sansserif">JavaScript 1.1, NES 2.0</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1197019" id="1197019"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1197021" id="1197021"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1193629" id="1193629"></a> <a name="Syntax" id="Syntax"></a> <span class="sansserif"><b>Syntax</b></span><br>
         <a name="1193630" id="1193630"></a> <span class="mono">toString()</span>
      </p>
      <p>
        <br>
         <a name="1193631" id="1193631"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1193632" id="1193632"></a> <span class="sansserif">None.</span>
      </p>
      <p>
        <br>
         <a name="1193633" id="1193633"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1199945" id="1199945"></a> <span class="sansserif">The <a href="function.html#1193137">Function</a> object overrides the <span class="mono">toString</span> method of the <a href="object.html#1193136">Object</a> object; it does not inherit <a href="object.html#1193350">Object.toString</a>. For <a href="function.html#1193137">Function</a> objects, the <span class="mono">toString</span> method returns a string representation of the object.</span>
      </p>
      <p>
        <a name="1199952" id="1199952"></a> <span class="sansserif">JavaScript calls the <span class="mono">toString</span> method automatically when a <a href="function.html#1193137">Function</a> is to be represented as a text value or when a <a href="function.html#1193137">Function</a> is referred to in a string concatenation.</span>
      </p>
      <p>
        <a name="1193639" id="1193639"></a> <span class="sansserif">For <a href="function.html#1193137">Function</a> objects, the built-in <span class="mono">toString</span> method decompiles the function back into the JavaScript source that defines the function. This string includes the <span class="mono">function</span> keyword, the argument list, curly braces, and function body.</span>
      </p>
      <p>
        <a name="1193640" id="1193640"></a> <span class="sansserif">For example, assume you have the following code that defines the <span class="mono">Dog</span> object type and creates <span class="mono">theDog,</span> an object of type <span class="mono">Dog</span>:</span>
      </p>
      <p>
        <a name="1193641" id="1193641"></a> <span class="mono">function Dog(name,breed,color,sex) {<br>
         &nbsp;&nbsp;&nbsp;this.name=name<br>
         &nbsp;&nbsp;&nbsp;this.breed=breed<br>
         &nbsp;&nbsp;&nbsp;this.color=color<br>
         &nbsp;&nbsp;&nbsp;this.sex=sex<br>
         }</span>
      </p>
      <p>
        <a name="1193642" id="1193642"></a> <span class="mono">theDog = new Dog("Gabby","Lab","chocolate","girl")</span>
      </p>
      <p>
        <a name="1193643" id="1193643"></a> <span class="sansserif">Any time <span class="mono">Dog</span> is used in a string context, JavaScript automatically calls the <span class="mono">toString</span> function, which returns the following string:</span>
      </p>
      <p>
        <a name="1193644" id="1193644"></a> <span class="mono">function Dog(name, breed, color, sex) { this.name = name; this.breed = breed; this.color = color; this.sex = sex; }</span>
      </p>
      <p>
        <br>
         <a name="1199973" id="1199973"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1199977" id="1199977"></a> <span class="sansserif"><a href="object.html#1193350">Object.toString</a></span>
      </p>
      <p>
        <br>
      </p>
      <p>
        <a name="1199980" id="1199980"></a> <a name="valueOf" id="valueOf"></a> <span class="sansserif"><b>valueOf</b></span>
      </p>
      <p>
        <a name="1199997" id="1199997"></a> <span class="sansserif">Returns a string representing the source code of the function.<br></span>
      </p>
      <p>
        <br>
        <br>
      </p>
      <table width="90%" border="1" cellpadding="5" cellspacing="0">
        <tr>
          <td valign="top">
            <p>
              <a name="1199983" id="1199983"></a> <span class="sansserif"><i>Method of</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1199988" id="1199988"></a> <span class="sansserif"><a href="function.html#1193137">Function</a></span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1199990" id="1199990"></a> <span class="sansserif"><i>Implemented in</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1199992" id="1199992"></a> <span class="sansserif">JavaScript 1.1</span> &nbsp;
            </p>
          </td>
        </tr>
        <tr>
          <td valign="top">
            <p>
              <a name="1199994" id="1199994"></a> <span class="sansserif"><i>ECMA version</i></span> &nbsp;
            </p>
          </td>
          <td valign="top">
            <p>
              <a name="1199996" id="1199996"></a> <span class="sansserif">ECMA-262</span> &nbsp;
            </p>
          </td>
        </tr>
      </table>
      <p>
        <br>
         <a name="1199998" id="1199998"></a> <a name="Syntax" id="Syntax"></a> <span class="sansserif"><b>Syntax</b></span><br>
         <a name="1199999" id="1199999"></a> <span class="mono">valueOf()</span>
      </p>
      <p>
        <br>
         <a name="1200000" id="1200000"></a> <a name="Parameters" id="Parameters"></a> <span class="sansserif"><b>Parameters</b></span><br>
         <a name="1200001" id="1200001"></a> <span class="sansserif">None</span>
      </p>
      <p>
        <br>
         <a name="1200002" id="1200002"></a> <a name="Description" id="Description"></a> <span class="sansserif"><b>Description</b></span><br>
         <a name="1231841" id="1231841"></a> <span class="sansserif">The <span class="mono">valueOf</span> method returns the following values:</span>
      </p>
      <ul>
        <li class="nobullet">
          <a name="1231842" id="1231842"></a>
        </li>
        <li>
          <span class="sansserif">For the built-in <span class="mono">Function</span> object, <span class="mono">valueOf</span> returns the following string indicating that the source code is not available:</span> 
          <p>
            <a name="1231843" id="1231843"></a> <span class="mono">&nbsp;&nbsp;&nbsp;function Function() {<br>
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[native code]<br>
             &nbsp;&nbsp;&nbsp;}</span>
          </p>
          <p>
            <a name="1231888" id="1231888"></a>
          </p>
        </li>
        <li>
          For custom functions, <span class="mono">toSource</span> returns the JavaScript source that defines the object as a string. The method is equivalent to the <span class="mono">toString</span> method of the function.
        </li>
      </ul><a name="1231889" id="1231889"></a> <span class="sansserif">This method is usually called internally by JavaScript and not explicitly in code.</span> 
      <p>
        <br>
         <a name="1231890" id="1231890"></a> <a name="See also" id="See also"></a> <span class="sansserif"><b>See also</b></span><br>
         <a name="1200023" id="1200023"></a> <span class="sansserif"><a href="function.html#1193615">Function.toString</a>, <a href="object.html#1193540">Object.valueOf</a></span>
      </p>
    </blockquote>
    <blockquote>
      <br>
       <b><a class="sansserifPurple" href="date.html">Previous</a></b>&nbsp;&nbsp;&nbsp;&nbsp; <a href="contents.html"><b class="sansserifPurple">Contents</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="ix.html"><b class="sansserifPurple">Index</b></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="java.html"><b class="sansserifPurple">Next</b></a> &nbsp;&nbsp;&nbsp;&nbsp; 
      <hr noshade="noshade" size="1">
      <span class="sansserif">Copyright &copy; 2000 <a href="http://www.netscape.com">Netscape Communications Corp.</a> All rights reserved.</span>
    </blockquote>
    <p class="alignright">
      <span class="sansserif">Last Updated <b>September 28, 2000</b></span>
    </p>
  </body>
</html>
